﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AbstractAndInterface
{
    /// <summary>
    /// 抽象类
    /// </summary>
    abstract class Phone
    {
        /// <summary>
        /// 抽象方法
        /// </summary>
        public abstract void Called();

        /// <summary>
        /// 虚方法，有方法体
        /// </summary>
        public virtual void VirtualMethod()
        {
            Console.WriteLine("class Phone VirtualMethod()");
        }
    }

    /// <summary>
    /// 接口
    /// </summary>
    interface IClock
    {
        void Clock();
    }

    class Nokia : Phone, IClock
    {
        /// <summary>
        /// 子类必须实现父类的抽象方法，需要用override重写
        /// </summary>
        public override void Called()
        {
            Console.WriteLine("NOKIA打电话没问题");   
        }

        /// <summary>
        /// 显式实现接口中的方法
        /// </summary>
        public void IClock.Clock()
        {
            Console.WriteLine("NOKIA有闹钟功能");   
        }

        /// <summary>
        /// 用override关键词重写虚方法
        /// 若此处不用override关键词，则phone.VirtualMethod();的结果为class Phone VirtualMethod()
        /// </summary>
        public override void VirtualMethod()
        {
            Console.WriteLine("class Nokia VirtualMethod()");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            IClock clock = new Nokia();
            clock.Clock();

            Phone phone = new Nokia();
            phone.Called();
            phone.VirtualMethod();//此处输出跟Nokia用什么关键词修饰VirtualMethod息息相关

            Nokia nokia = new Nokia();
            nokia.VirtualMethod();

        }
    }
}
